#! env python

from jinja2 import Template


class ExecMapping(object):
    def __init__(self, iter_space, thd_space) -> None:
        

class SharedMem(object):
    def __init__(self, blk_bufsize, warp_bufsize, thd_bufsize, 
                       blk_buftype, warp_buftype, thd_buftype) -> None:
        self.thd_buf = thd_bufsize
        self.warp_buf = warp_bufsize
        self.blk_buf = blk_bufsize
        self.thd_buf_type = thd_buftype
        self.warp_buf_type = warp_buftype
        self.blk_buf_type = blk_buftype
    
    def buffer_size(self, blkdim):
        thds = 1
        for i in blkdim:
            thds *= i
        
        blkb = 1
        for i in self.blk_buf:
            blkb *= i
        
        warpb = 1
        for i in self.warp_buf:
            warpb *= i
        
        thdb = 1
        for i in self.thd_buf:
            thdb *= i
        
        return blkb + warpb * thds//32 + thdb * thds
    
    @property
    def shared_buffer_decl(self):
        return "extern __shared__ char _sh[];"

    @property
    def shared_buffer_init(self):
        
        

class Var(object):
    def __init__(self, var_name, unroll, veclen, cache_schema) -> None:
        self.var_name = var_name
        assert unroll in [0, 2, 4]
        assert veclen in [0, 2, 4]
        assert cache_schema in ['none', 'shared', 'shfl']

        self.unroll = unroll
        self.veclen = veclen 
        self.cache_schema = cache_schema

    def write(self, offset):
        return 
    
    @property
    def arg(self):
        return self.var_name

    @property
    def reg_val(self):
        return self.var_name + '_tmp'